<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        添加优惠券
    </title>
    <%--<meta name="renderer" content="webkit">--%>
    <%--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">--%>
    <%--<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">--%>
    <%--<meta name="apple-mobile-web-app-status-bar-style" content="black">--%>
    <%--<meta name="apple-mobile-web-app-capable" content="yes">--%>
    <%--<meta name="format-detection" content="telephone=no">--%>
    <link rel="stylesheet" href="../../../backstage/css/x-admin.css" media="all">
</head>

<body>
<div class="x-nav">
    <span class="layui-icon-help">
        <a >带*为必填项</a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
    </a>
</div>
<div class="x-body">
    <form id="addItem" class="layui-form layui-form-pane"  enctype="multipart/form-data">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <input type="hidden" name="id" value="{$art.id}">

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>优惠券名称
                        </label>
                        <div class="layui-input-block">
                            <input id="itemName" type="text" name="itemName" required="" lay-verify="required"autocomplete="off" class="layui-input-add" maxlength="20" >
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>生效时长(天)
                        </label>
                        <div class="layui-input-block">
                            <input id="howLong" type="number" name="howLong" required="" lay-verify="required" autocomplete="off" class="layui-input-add"
                                   oninput = "if(value>99999)value=99999;value=value.replace(/[^\d]/g,'')" >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>价格(元)
                        </label>
                        <div class="layui-input-block">
                            <input id="price" type="number" name="price" required="" lay-verify="required"
                                   autocomplete="off" class="layui-input-add"
                                   oninput = "if(value>99999)value=99999;value=value.replace(/[^\d]/g,'')">
                        </div>
                    </div>
                    <%--<div class="layui-form-item">--%>
                        <%--<label class="layui-form-label">--%>
                            <%--<span class='x-red'>*</span>状态--%>
                        <%--</label>--%>
                        <%--<div class="layui-input-inline"  >--%>
                            <%--<select name="category_id" id="state">--%>
                                <%--<option value="">---请选择状态---</option>--%>
                                <%--<option value="有效">有效</option>--%>
                                <%--<option value="已下架">已下架</option>--%>
                            <%--</select>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>消耗积分
                        </label>
                        <div class="layui-input-block">
                            <input id="credit" type="number" name="credit"  required="" lay-verify="required" autocomplete="off" class="layui-input-add"  oninput="if(value>99999)value=99999;value=value.replace(/[^\d]/g,'')" >
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>描述
                        </label>
                        <div class="layui-input-block">
                            <textarea id="description"  name="description" required=""
                                      class="layui-input-add"  maxlength="100"
                                      style="height:100px;" >
                                </textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>使用说明
                        </label>
                        <div class="layui-input-block">
                            <input id="howUse" type="text" name="howUse" required="" lay-verify="required" autocomplete="off" class="layui-input-add" maxlength="30">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'></span>备注
                        </label>
                        <div class="layui-input-block">
                            <input id="remark" type="text" name="remark" autocomplete="off" class="layui-input-add" maxlength="30"  >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <input id="add" type="button" class="layui-btn"  lay-submit="add" value="添加">  </input>
                    </div>
                    <div style="height:100px;"></div>
                </div>

            </div>
        </div>
    </form>
</div>
<script src="../../../backstage/js/jquery.min.js"></script>
    <script src="../../../backstage/lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../backstage/js/x-layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'layer'], function() {
            $ = layui.jquery;
            var form = layui.form(),
            layer = layui.layer;


            form.verify({
                howLong: function(value){
                    if(value.length<=0){
                        return '使用时长不能为空';
                    }
                }
            });
            form.verify({
                price: function(value){
                    if(value.length<=0){
                        return '价格不能为空';
                    }
                }
            });
            form.verify({
                credit: function(value){
                    if(value.length<=0){
                        return '积分不能为空';
                    }
                }
            });
            form.verify({
                description: function(value){
                    if(value.length<=0){
                        return '描述不能为空';
                    }
                }
            });
            form.verify({
                howUse: function(value){
                    if(value.length<=0){
                        return '如何使用不能为空';
                    }
                }
            });

            $("#add").click(function () {

                var couponName = $.trim($("#itemName").val());

                var howLong = $.trim($("#howLong").val());

                var price = $.trim($("#price").val());
                var credit = $.trim($("#credit").val());
                var remark = $.trim($("#remark").val());
                var description = $.trim($("#description").val());
                var howUse = $.trim($("#howUse").val());

                if (couponName==""){
                    layer.msg('商品名不能为空',{icon:5,time:2000});
                    return false;
                }
                if (howLong==""){
                    layer.msg('使用时长不能为空',{icon:5,time:2000});
                    return false;
                }
                if (price==""){
                    layer.msg('价格不能为空',{icon:5,time:2000});
                    return false;
                }
                if (credit==""){
                    layer.msg('积分不能为空',{icon:5,time:2000});
                    return false;
                }
                if (description==""){
                    layer.msg('描述不能为空',{icon:5,time:2000});
                    return false;
                }
                if (howUse==""){
                    layer.msg('使用方式不能为空',{icon:5,time:2000});
                    return false;
                }

                $.ajax({
                    type:'POST',
                    url:'/member/memberManagement/insertCoupon',
                    data:{couponName:couponName,description:description,
                        howLong:howLong,price:price,
                        credit:credit,howUse:howUse,remark:remark} ,
                    dataType:"json",

                    error: function () {
                        alert("失败");
                    },
                    success:function(data){
                        console.log(data);
                        if(data){
                            alert("添加成功");
                        }else {
                            alert("插入失败");
                        }
                            location.reload();
                    }
                });
            });
        });
    </script>
</body>

</html>